import { BaseCommand } from '@amcax/base';
import { editLine } from '@app-base/common/utils';
import { sketchEventCenter } from '@app-base/environments/nextcad/events/SketchEventCenter';

export const cmdConstLine: BaseCommand = {
  id: 'CmdConstLine',
  group: 'sketch',
  label: 'command.construction-line',
  icon: 'commands/sketch/construction-line',
  standalone: true,
  invoke: () => {
    const lineList = sketchEventCenter()
      .getSelectedModels()
      ?.filter((item) => item.type !== 'Point');
    if (lineList?.length !== 0) {
      const construction = lineList[0]?.curveStyle !== 0 ? 0 : 1;
      for (let i = 0; i < lineList?.length; i++) {
        editLine(
          {
            curve: lineList[i].id,
            curveStyle: construction,
          },
          lineList[i].type,
        );
        lineList[i].curveStyle = construction;
      }
      sketchEventCenter().setLineType(construction);
    } else {
      const lineType = sketchEventCenter().getLineType() === 0 ? 1 : 0;
      sketchEventCenter().setLineType(lineType);
    }
  },
};
